﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MadLibrary.Net.Ndmp
{
    /// <summary>
    /// Holds the command for NDM protocol communication.
    /// </summary>
    public enum NdmpCommand
    {
        /// <summary>
        /// Represents select command.
        /// </summary>
        Select,
        /// <summary>
        /// Represents put command.
        /// </summary>
        Put,
        /// <summary>
        /// Represents delete command.
        /// </summary>
        Delete,
        /// <summary>
        /// Represents update command.
        /// </summary>
        Update,
        /// <summary>
        /// Represents unknown command.
        /// </summary>
        Unknown
    }
    /// <summary>
    /// Serves as manager which transforms NdmpCommand to different forms.
    /// </summary>
    public static class NCManager
    {
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents specified NdmpCommand.
        /// </summary>
        /// <param name="cmd">The NdmpCommand.</param>
        /// <returns>
        /// A <see cref="System.String"/> that represents specified NdmpCommand.
        /// </returns>
        public static string ToString(NdmpCommand cmd)
        {
            switch (cmd)
            { 
                case NdmpCommand.Select:
                    return "SELECT";
                case NdmpCommand.Put:
                    return "PUT";
                case NdmpCommand.Delete:
                    return "DELETE";
                case NdmpCommand.Update:
                    return "UPDATE";
                case NdmpCommand.Unknown:
                default:
                    return "Unknown";
            }
        }
        /// <summary>
        /// Parses specified input to NdmpCommand.
        /// </summary>
        /// <param name="Input">The input.</param>
        /// <returns>Parsed NdmpCommand.</returns>
        public static NdmpCommand ToCommand(string Input)
        {
            NdmpCommand tcmd = NdmpCommand.Unknown;
            switch (Input.ToUpper())
            {
                case "SELECT":
                    tcmd = NdmpCommand.Select;
                    break;
                case "PUT":
                    tcmd = NdmpCommand.Put;
                    break;
                case "DELETE":
                    tcmd = NdmpCommand.Delete;
                    break;
                case "UPDATE":
                    tcmd = NdmpCommand.Update;
                    break;
            }
            return tcmd;
        }
    }
}
